package com.wang.springboot.template01.test.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

/**
 * @author: wang
 * @date: 2021/8/25 15:46
 * @description:
 */
@Configuration
@Aspect
public class ControllerAop {

    @Autowired(required = false)


    @Pointcut("execution(* *..controller..*.*(..))")
    public void pointcut(){}

    @Pointcut("execution(* *..controller..*.*(..))")
    public void pointcut1(){}

    @Before("pointcut()")
    public void bf(){
        System.out.println("前置通知切入成功！ ");
    }

    @After("pointcut1()")
    public void af(){
        System.out.println("后置通知切入成功！ ");
    }

    @AfterReturning("pointcut()")
    public void ar(){
        System.out.println("afterReturn通知切入成功!");
    }

    @AfterThrowing("pointcut1()")
    public void at(){
        System.out.println("afterThrowing通知切入成功！");
    }

    @Around("pointcut1()")
    public Object around(ProceedingJoinPoint pjp){
        Object result = null;
        try {
            System.out.println("环绕前置通知！");
            result = pjp.proceed();
            System.out.println("环绕后置通知！");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("环绕异常通知！");
        }finally {
            System.out.println("环绕返回值后的通知");
        }
        return result;
    }


}
